import Http from '@/utils/http.js'
import { IsNull } from '@/utils/utils'
import http from '@/utils/http.js'

export default {
  // 是否有公司可编辑的权限
  isComponyEditDataRole(companyID) {
    return Http.GET(`/api/Acl/IsComponyEditDataRole/${companyID}`)
  },
  // 获取子成员
  getChildUsers(param) {
    return Http.POST(`api/Organization/GetChildUsers`, param)
  },
  // 是否存在成员、子部门或组
  exsitChildren(unitID) {
    return Http.GET(`api/Organization/ExsitChildren/${unitID || ''}`)
  },
  // 删除成员、部门或组
  deleteUnitById(unitID) {
    return Http.GET(`api/Organization/DeleteUnitById/${unitID || ''}`)
  },
  // 添加成员到部门
  addUserForDepartment(departmentID, userIDs) {
    if (IsNull(departmentID)) {
      return Promise.reject('部门ID不能为空！')
    }
    if (IsNull(departmentID) || (Array.isArray(userIDs) && userIDs.length <= 0)) {
      return Promise.reject('人员不能为空！')
    }
    return Http.POST('api/Organization/UpdateUserDept', {
      DeptId: departmentID,
      UserIdList: [...userIDs]
    })
  },
  isRoleByCode(roleCode) {
    return Http.GET(`api/Organization/IsRoleByCode/${roleCode}`)
  },
  getUserSysRoles() {
    return Http.GET(`api/System/GetUserSysRoles`)
  },
  getDisabledUsers(param) {
    return Http.POST(`api/Organization/GetDisabledUsers`, param)
  },
  searchDisabledUsers(PagingInfo, SearchCondition) {
    return Http.POST(`api/Organization/GetDisabledUsers`, {
      PagingInfo,
      SearchCondition
    })
  },
  activeUser(ObjectID) {
    return Http.GET(`api/Organization/ActiveUser/${ObjectID}`)
  },
  getCategoryList(param) {
    return Http.POST(`api/Organization/GetCategoryList`, param)
  },
  searchCategoryList(PagingInfo, SearchCondition) {
    return Http.POST(`api/Organization/GetCategoryList`, {
      PagingInfo,
      SearchCondition
    })
  },
  isCategoryCodeSole(Code) {
    return Http.GET(`api/Organization/IsCategoryCodeSole/${Code}`)
  },
  addCategory(param) {
    return Http.POST(`api/Organization/AddCategory`, param)
  },
  editCategory(param) {
    return Http.POST(`api/Organization/EditCategory`, param)
  },
  delCategory(ids) {
    return Http.POST(`api/Organization/DelCategory`, ids)
  },
  getRoleList(param) {
    return Http.POST(`api/Organization/GetRoleList`, param)
  },
  searchRoleList(pagingInfo, filterRole, searchCondition) {
    return Http.POST(`api/Organization/GetRoleList`, {
      PagingInfo: pagingInfo,
      FilterRole: filterRole,
      SearchCondition: searchCondition
    })
  },
  isOrgRoleCodeSole(Code) {
    return Http.GET(`api/Organization/isOrgRoleCodeSole/${Code}`)
  },
  addRole(param) {
    return Http.POST(`api/Organization/AddOrgRole`, param)
  },
  editRole(param) {
    return Http.POST(`api/Organization/EditOrgRole`, param)
  },
  delRole(ids) {
    return Http.POST(`api/Organization/DelOrgRoles`, ids)
  },
  getRoleUserList(PagingInfo, SearchCondition, FilterRole = false) {
    return Http.POST(`api/Organization/getRoleUserList`, {
      PagingInfo,
      SearchCondition,
      FilterRole
    })
  },
  addRoleUser(param) {
    return Http.POST(`api/Organization/AddRoleUsers`, param)
  },
  editRoleUser(param) {
    return Http.POST(`api/Organization/EditRoleUsers`, param)
  },
  delRoleUser(RoldID, param) {
    return Http.POST(`api/Organization/DelRoleUser/${RoldID}`, param)
  },
  getFieldSetsUser() {
    return Http.GET(`api/System/GetFieldSets/User`)
  },
  saveFieldSetsUser(param) {
    return Http.POST(`api/System/SaveFieldSets/User`, param)
  },
  saveExtendSets(param) {
    return Http.POST(`api/System/SaveExtendSets`, param)
  },
  getExtendSets() {
    return Http.GET(`api/System/GetExtendSets`)
  },
  getExtendSet() {
    return Http.GET(`api/System/GetExtendSet`)
  },
  getOrgSyncInfo() {
    return http.GET(`api/System/GetEntOrganizationInfo`)
  },
  getDBconfigList() {
    return http.GET(`api/DataSource/LoadDbConfigList`)
  },
  doKafkaFullSync(isFullSync) {
    return http.GET(`api/Organization/doKafkaFullSync/${isFullSync}`)
  },
  isAdmin() {
    return Http.GET(`api/Organization/IsAdmin`)
  },
  checkAdmin(code) {
    return Http.GET(`api/Organization/CheckAdmin/${code}`)
  },
  getSystemAclList(param) {
    return Http.POST(`api/Organization/GetSystemAclList`, param)
  },
  saveSystemAcl(id) {
    return Http.GET(`api/Organization/SaveSystemAcl/${id}`)
  },
  delSystemAcl(ids) {
    return Http.POST(`api/Organization/DelSystemAcl`, ids)
  },
  getSystemAclListBySearch(param, searchStr) {
    if (IsNull(searchStr)) {
      return this.getSystemAclList(param)
    } else {
      return Http.POST(
        `api/Organization/GetSystemAclList/${encodeURIComponent(searchStr)}`,
        param
      )
    }
  }
}
